<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>
<link href="${initParam.url }/statics/css/detail.css" rel="stylesheet">
<link href="${initParam.url }/statics/css/compilewrite.css" rel="stylesheet">
<script src="${initParam.url}/statics/js/jquery-1.12.4.js"></script>
	<script>
	$(document).ready(function(){
		$("#btn").click(function(){		
			var flag = true;
			if (!checkpassword()) {
				flag = false;
			}
			if (!checkEmail()) {
				flag = false;
			}
			if (!checkPass()) {
				flag = false;
			}
			if (!checkyuan()) {
				flag = false;
			}
			if(flag==true){
				
				$("#jo").submit();
			}	
		})
		$("#password2").blur(checkpassword);
		$("#password").blur(checkPass);
		$("#email").blur(checkEmail);
		$("#yuan").blur(checkyuan);
	})
		//验证密码
		function checkPass() {
			var $pwd = $("#password");
			var $divID = $("#DivPassword");
			$divID.html("");
			if ($pwd.val() == "") {
				$divID.html("密码不能为空");
				return false;
			}
			return true;
		}
	
		function checkpassword() {
			var $pwd = $("#password");
			var $repwd = $("#password2"); 
			var $divID = $("#DivPassword2");
			$divID.html("");
			if ($pwd.val() != $repwd.val()) {
				$divID.html("两次输入的密码不一致");
				return false;
			}
			return true;
		}
		//验证Email
		function checkEmail() {
			var $mail = $("#email");
			var $divID = $("#DivEmail");
			$divID.html("");
			if ($mail.val() == "") {
				return true;
			}
			if ($mail.val().indexOf("@") == -1) {
				$divID.html("Email格式不正确，必须包含@");
				return false;
			}
			if ($mail.val().indexOf(".") == -1) {
				$divID.html("Email格式不正确，必须包含.");
				return false;
			}
			return true;
		}
		
		function checkyuan() {
			var $mail = $("#yuan");
			var $mails = $("#yuana");
			var $divID = $("#Divyuan");
			$divID.html("");
			if ($mail.val() == "") {
				$divID.html("请输入原密码");
				return false;
			}
			if ($mail.val()!=$mails.val()) {
				$divID.html("请输入正确的原密码");
				return false;
			}
			
			return true;
		}
	</script>
</head>

<body>
	<div style="width: 1090px;height: 480px;background-color: #FFF;margin: 20px;">
		<h4
			style="background-color: #9FB2C2; padding-left: 10px; color: #516D8A; line-height: 40px;">
			<img alt="" src="${initParam.url}/statics/images/title.jpg">
			编辑物管信息
		</h4>
		
		<div class="sp">
					<form action="docompilewrite" method="post"  id="jo">
						
					    <input type="hidden" id="yuana" value="${user.passWord}">
							<table>
								<tr>
									<td class="tr-1">用户名:</td>
									<td><input class="tr-2 form-control " style="width: 220px;height: 25px;display: inline;" name="name" id="name" type="text" value="${user.userName }" readonly />&nbsp;<span id='DivUsername'></span></td>
									
						
								<tr>
									<td class="tr-1">原密码:</td>
									<td><input class="tr-2 form-control" style="width: 220px;height: 25px;display: inline;"id="yuan"  type="password" value=""  />&nbsp;<span id='Divyuan'></span>

								<tr>
								
								<tr>
									<td class="tr-1">新密码:</td>
									<td><input class="tr-2 form-control" style="width: 220px;height: 25px;display: inline;" name="password" id="password" type="password"  />&nbsp;<span id='DivPassword'></span></td>
								</tr>
								
								<tr>
									<td class="tr-1">确认密码:</td>
									<td><input class="tr-2 form-control" style="width: 220px;height: 25px;display: inline;" name="password2" id="password2" type="password"  />&nbsp;<span id='DivPassword2'></span></td>
								</tr>
								<tr>
									<td class="tr-1">邮箱地址:</td>
									<td><input class="tr-2 " style="width: 220px;height: 25px;display: inline;" name="email" id="email" type="text"  />&nbsp;<span id='DivEmail'></span></td>
								</tr>
								<tr>
									<td colspan="2" class="td-1">
									<input type="button"  class="btn btn-default" value="确定" id="btn"> <input type="button" class="btn btn-default" onclick="history.go(-1)" value="取消"></td>
								</tr>
							</table>
								<span style="color:red;">${error }</span>
						</form>
			
		</div>
	</div>
</body>
</html>